package com.navinfo.routeplan.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MainActivityViewModel: ViewModel() {
    private val settingLiveData: MutableLiveData<Map<String, String>> = MutableLiveData() // 设置界面对应的数据
    fun updateSettingLiveData(settingMap: Map<String, String>) {
        settingMap.forEach {
            // 创建一个新的HashMap来存储更新后的数据
            val updatedSettings = HashMap<String, String>()

            // 将settingLiveData中的数据添加到新的HashMap中
            settingLiveData.value?.forEach { entry ->
                updatedSettings[entry.key] = entry.value
            }

            // 将settingMap中的数据增量添加到新的HashMap中
            settingMap.forEach { entry ->
                updatedSettings[entry.key] = entry.value
            }

            // 使用postValue更新settingLiveData的值
            settingLiveData.postValue(updatedSettings)
        }
    }
}